package com.rgst.dao.repository;

import java.util.Set;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import com.rgst.dao.entity.UserRole;

/**
 * Created by tancw on 2019/12/5.
 */
public interface UserRoleRepository extends JpaRepository<UserRole,Long> {
    @Query(nativeQuery = true,
        value="SELECT r.role_name FROM sec_role r, sec_user u,sec_user_role ur WHERE ur.role_id = r.id AND ur.user_id =u.id AND u.`username` = ?1")
    Set<String> findAllRoleByUsername(String username);

    @Query(nativeQuery = true,
            value = "SELECT p.`permission` FROM sec_role_permission rp, sec_user u,sec_user_role ur ,sec_permission p\n" +
                    "WHERE ur.role_id = rp.`role_id` AND ur.user_id =u.id AND p.`id` = rp.`permission_id` AND u.`username` = ?1"
    )
    Set<String> findAllPermissionByUsername(String username);
}
